/*
 * faultInjector.cc
 *
 *  Created on: Nov 26, 2012
 *      Author: aguerreiro
 */

#include "faultInjector.h"
#include "p802_15_4pkt.h"
//#include "p802_15_4mac.h"
//#include "p802_15_4phy.h"

Packet* corruptFrame(Packet *p) {


	fprintf(stdout, "\n [%f] inside sendoverhandler ... \n", CURRENT_TIME);
//	fprintf(stdout, "\n  the value of beaconCorrupt is %d \n", activeFault);
	if (activeFault) {
		fprintf(stdout, "\n corrupting the beacon.. \n ");
		HDR_CMN(p)->error()=1;
		fprintf(stdout, "setting the error bit to %d \n", HDR_CMN(p)->error());
	}
	else
	HDR_CMN(p)->error() = 0;

	return p;
}

void randomCorruption(int seed) {

	double r;

	srand(seed);
	r = ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
	//rand_num=r;
}

void enableFaultInjector() {
	activeFault = true;
}

void disableFaultInejctor() {
	activeFault = false;
}
